/**
 * index.js
 * import title from './title.js'
 */

/**
  * title.js
  * module.exports = {
      age: 'age',
      name: 'name'
    }
*/

/**
 * require.r  -->  标识这是一个esModule模块
 * require.d  -->  将导出的内容进行赋值
 * require.n  -->  需要兼容获取default的内容
 * webpack在ast解析时解析到`import`语法时，就会知道该模块是esModule模块，会使用`require.r`进行标记
 */

var modules = {
  "./src/title": function(module, exports, require){
    module.exports = {
      age: 'age',
      name: 'name'
    }
  }
}

var cache = {}

function require(moduleId){
  if(cache[moduleId] != undefined){
    return cache[moduleId]
  }
  var module = cache[moduleId] = {exports: {}}
  modules[moduleId](module,module.exports,require)
  return module.exports
}

require.r = function(exports){
  Object.defineProperty(exports, Symbol.toStringTag, {value: 'Module'}); // [object Module]
  Object.defineProperty(exports, '__esModule', {value: true})
}

require.d = function(exports, defines){
  for (const key in defines) {
   Object.defineProperty(exports, key, {
     get: defines[key],
     enumerable: true
   })
  }
}

require.n = function(module){
  var getter = module.__esModule? () => module.default: () => module
  return getter
}

var exports = {}

require.r(exports)
var title = require('./src/title')
var title_default = require.n(title)
console.log(JSON.stringify(title))
console.log(title_default());
console.log(title.age);